#!/usr/bin/env bash
#-------------------------------------------------------
#	FileName	: push.sh
#	Author		：hpy
#	Date		：2024年03月25日
#	Description	：git 规范化推送 
#   https://zhuanlan.zhihu.com/p/182553920
#-------------------------------------------------------

git_prj_name="wls2-install"


#-------------------------------------------------------
# 终端分割线
#-------------------------------------------------------
function fg() {
    shellwidth=`stty size|awk '{print $2}'`
    yes "-" | sed $shellwidth'q' | tr -d '\n'
}
#-------------------------------------------------------
# 提交到的平台选择
#-------------------------------------------------------
function select-platform() {
    # echo " ------------ "
    fg
    PS3="选择你要PUSH的平台序号:"
    select i in all gitee gitea exit 
    do 
        if [[ $i == "exit" ]] ; then 
            exit 0
        elif [[ $i == "gitea" ]] ; then
            git remote set-url origin  https://yuan_hp:5bb75321ff4fef60ff9e7ab47692b697@gitee.com/yuan_hp/$git_prj_name.git
            break
        elif [[ $i == "gitee" ]] ; then 
            git remote set-url origin  https://yuan_hp:5bb75321ff4fef60ff9e7ab47692b697@gitee.com/yuan_hp/$git_prj_name.git
            break
        elif [[ $i == 'all' ]] ; then
            git remote set-url origin  http://yhp:c367aca0a07d0779f62208d8bfe24f4d1fe8a9c8@120.46.47.28:3000/yhp/$git_prj_name.git && git push \
            && git remote set-url origin  https://yuan_hp:5bb75321ff4fef60ff9e7ab47692b697@gitee.com/yuan_hp/$git_prj_name.git && git push
            exit 0
        fi    
    done 
}

#-------------------------------------------------------
# commit的类型
#-------------------------------------------------------
function commit_type() {
    # echo " -------------------- "
    
    fg
    PS3="commit的类型:"
    select i in exit "新功能" "直接一次修复bug" "产生diff多次修复bug" "文档" "格式" "重构" "优化" "测试" "回滚到上一个版本" "代码合并" "同步Bug"
    do 
        if [[ $i == "exit" ]] ; then 
            exit 0
        elif [[ $i == "新功能" ]] ; then
            git commit -m "feat:$*" 
            break
        elif [[ $i == "直接一次修复bug" ]] ; then
            git commit -m "fix:$*" 
            break
        elif [[ $i == "产生diff多次修复bug" ]] ; then
            git commit -m "to:$*" 
            break
        elif [[ $i == "文档" ]] ; then
            git commit -m "docs:$*" 
            break
        elif [[ $i == "格式" ]] ; then
            git commit -m "style:$*" 
            break
        elif [[ $i == "重构" ]] ; then
            git commit -m "refactor:$*" 
            break
        elif [[ $i == "优化" ]] ; then
            git commit -m "perf:$*" 
            break
        elif [[ $i == "测试" ]] ; then
            git commit -m "test:$*" 
            break
        elif [[ $i == "回滚到上一个版本" ]] ; then
            git commit -m "revert:$*" 
            break
        elif [[ $i == "代码合并" ]] ; then
            git commit -m "merge:$*" 
            break
        elif [[ $i == "同步Bug" ]] ; then
            git commit -m "sync:$*" 
            break
        fi    
    done 
}

# ------------------------------------------------------------
test ${#*} -eq 0 && echo "Info:请添加commit描述" && exit 1
git status
git add .
# git commit -m "Note:$*"
commit_type $*
select-platform
git push



